﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace EarringsBackEnd
{
    public static class ValueUtil
    {
        public static string GetNextKey(string type,string shrtName)
        {
            string nextKey = string.Empty;
            MasterDataManagement dtMgmt = MasterDataManagement.InstanceCreation();
            string[] value = dtMgmt.GetMaxKey(type).Split('-');
            
            if(value.Length ==1)
            {
                nextKey = string.Format("{0}-{1}", shrtName, (1).ToString().PadLeft(4, '0'));
            }
            else
            {
                nextKey = string.Format("{0}-{1}", value[0], (int.Parse(value[1].ToString()) + 1).ToString().PadLeft(4, '0'));
            }
            
            return nextKey;
        }

        public static string GetNextKeyEarrings(string styleId,string styles)
        {
            string nextKey = string.Empty;
            MasterDataManagement dtMgmt = MasterDataManagement.InstanceCreation();
            string[] value = dtMgmt.GetMaxKeyEarrings(styleId).Split('-');

            if (value.Length == 1)
            {
                nextKey = string.Format("{0}-{1}", styles, (1).ToString().PadLeft(4, '0'));
            }
            else
            {
                nextKey = string.Format("{0}-{1}", value[0], (int.Parse(value[1].ToString()) + 1).ToString().PadLeft(4, '0'));
            }

            return nextKey;
        }

        
    }
}
